<template>
  <div class="app-container">
    <el-row class="mb20">
      <el-form :model="queryParams" :inline="true" ref="queryForm">
        <el-form-item label="类型" prop="freezeType">
          <el-select v-model="queryParams.freezeType" placeholder="请选择类型" clearable>
            <el-option label="冻结" value="1"></el-option>
            <el-option label="解冻" value="2"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="开门时间" prop="openTime">
          <el-date-picker v-model="dateRange" type="daterange" range-separator="至"
                          start-placeholder="开始日期" end-placeholder="结束日期"
                          value-format="yyyy-MM-dd"
          ></el-date-picker>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" size="mini" @click="handleSearch">搜索</el-button>
          <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
          >重置
          </el-button
          >
        </el-form-item>
      </el-form>
    </el-row>
    <el-table v-loading="loading" :data="list">
      <el-table-column label="类型" prop="type">
        <template slot-scope="scope">
          <span>{{ freezeTypeMap[scope.row.freezeType] ? freezeTypeMap[scope.row.freezeType] : '' }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作方式" prop="operationType">
        <template slot-scope="scope">
          <span>{{ operationTypeMap[scope.row.operationType] ? operationTypeMap[scope.row.operationType] : '' }}</span>
        </template>
      </el-table-column>
      <el-table-column label="时间" prop="openTime">
        <template slot-scope="scope">
          {{ scope.row.createTime | formatDate('YYYY-MM-DD HH:mm') }}
        </template>
      </el-table-column>
    </el-table>
    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum"
                :limit.sync="queryParams.pageSize" @pagination="getList"
    />
  </div>

</template>

<script>
import { getFreezeRecord } from '@/api/smartLock/lockManage'

export default {
  name: 'freeze-open-record',
  props: {
    data: {
      default: undefined
    }
  },
  data() {
    return {
      list: [],
      loading: false,
      total: 0,
      dateRange:[],
      queryParams: {
        freezeType: '',// 类型
        lockId:this.data.lockId,
        pageNum: 1,
        pageSize: 10
      },
      // 类型映射
      freezeTypeMap: {
        '1': '冻结',
        '2': '解冻'
      },
      // 开门方式映射
      operationTypeMap: {
        '1': '自动操作',
        '2': '手动操作'
      }
    }
  },
  created() {
    console.log('created')
    this.getList()
  },
  methods: {
    handleSearch() {
      this.queryParams.pageNum = 1
      this.getList()
    },
    resetQuery() {
      this.dateRange = [];
      this.resetForm('queryForm')
      this.handleSearch()
    },
    getList() {
      this.loading = true
      getFreezeRecord(this.addDateRange(this.queryParams, this.dateRange)).then(response => {
        this.list = response.rows
        this.total = response.total
        this.loading = false
      }).catch(error=>{
        console.log(error)
        this.list = []
        this.total = 0
        this.loading = false
      })
    }
  }
}
</script>

<style scoped lang="scss">

</style>
